<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Shopping list</title>
</head>
<body>
	<h1>what to buy</h1>
	<p title="a gentle reminder">Don't forget to buy this stuff</p>
	<ul id="purchases">
		<li>a tin of beans</li>
		<li class="sale">Cheese</li>
		<li class="sale important">Milk</li>
	</ul>
	<script type="text/javascript">
		/* 	返回id为“purchase“的document类型*/
		//alert(typeof document.getElementById("purchases"));
		/* 返回tag为"li"的长度 */
		//alert(document.getElementsByTagName("li").length);
		for ( var i = 0; i < document.getElementsByTagName("li").length; i++) {
			//alert(typeof document.getElementsByTagName("li")[i]);
		}
		function getElementsByClassName(node, classname) {
			if (node.getElementsByClassName) {
				//use the existing method
				return node.getElementsByClassName(classname);
			} else {
				var results = new Array();
				//the wildcard will give you all the elements of this node
				var elems = node.getElementsByTagName("*");
				for(var i=0;i<elems.length;i++){
					if(elems[i].className.indexof(classname)!=-1){
						results[results.length]=elems[i];
					}
				}
				return results;
			}
		}
		//get the node
		var shopping = document.getElementById("purchases");
		
 		var sales= getElementsByClassName(shopping,"sale");
		var paras = document.getElementsByTagName("p");
		for(var i=0;i<paras.length;i++){
			var title_text = paras[i].getAttribute("title");
			  if (title_text != null) {
				alert(title_text);
			  }
		}
		shopping.setAttribute("title","a list of goods");
		alert(shopping.getAttribute("title"));
	</script>
</body>
</html>